package com.ay.wiki_plt.job;

import com.ay.wiki_plt.service.EbookSnapshotService;
import com.ay.wiki_plt.utils.SnowFlake;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class EbookSnapshotJob {

    @Resource
    private EbookSnapshotService ebookSnapshotService;

    @Resource
    private SnowFlake snowFlake;

    /*自定义corn表达式*/
    @Scheduled(cron = "0/5 * * * * ?")
    public void doSnapshot(){
        //增加日志流水号
        MDC.put("LOG_ID", String.valueOf(snowFlake.nextId()));
        log.info("生成今日电子书快照开始");
        long start = System.currentTimeMillis();
        ebookSnapshotService.genSnapshot();
        log.info("生成今日电子书快照结束,耗时:{}毫秒",System.currentTimeMillis() - start);
    }

}
